package sdk;

public class Element
{
	private String value;
	private int xPos;
	private int yPos;
	private Square square;
	private VectorSDK guess;
	private VectorSDK row;
	private VectorSDK column;
	private int howManyGuess;
	
	public Element(String value, int xPos,int yPos){
		this.value=value;
		this.xPos=xPos;
		this.yPos=yPos;
		this.square=new Square();
		this.guess=new VectorSDK();
	}

	public String getValue()
	{
		return value;
	}

	public void setValue(String value)
	{
		this.value = value;
	}

	public int getxPos()
	{
		return xPos;
	}

	public void setxPos(int xPos)
	{
		this.xPos = xPos;
	}

	public int getyPos()
	{
		return yPos;
	}

	public void setyPos(int yPos)
	{
		this.yPos = yPos;
	}

	public Square getSquare()
	{
		return square;
	}

	public void setSquare(Square square)
	{
		this.square = square;
	}

	public VectorSDK getRow()
	{
		return row;
	}

	public void setRow(VectorSDK row)
	{
		this.row = row;
	}

	public VectorSDK getColumn()
	{
		return column;
	}

	public void setColumn(VectorSDK column)
	{
		this.column = column;
	}

	@Override
	public String toString()
	{
		String res="";
		res="["+xPos+" "+yPos+"]\n"+
			"col:"+
			column
			+"\n"+
			"row:"+row+"\n"+
			"sqr:\n"+square+"\n"+
			"gus:\n"+guess+"\n";
		return res;
	}
	
	/**
	 * valorize the vectro guess with all the possible values
	 */
	public void elaborateGuess(){
		if(!value.equalsIgnoreCase("*")){
			howManyGuess=0;
			String[] a = {"","","","","","","","",""};
			guess.setElement(a);
			return;
		}
		String rowGuess= row.getLine();
		String colGuess= column.getLine();
		String sqrGuess= square.getLine();
		howManyGuess=9;
		for(int i=0;i<9;i++){
			String v=(i+1)+"";
			guess.getVectorSDK()[i]=v;
			if(!rowGuess.contains(v) || !colGuess.contains(v) || !sqrGuess.contains(v) ){
				guess.getVectorSDK()[i]="";
				howManyGuess--;
			}
		}
	}

	public void printGuess(int level)
	{
		String res="";
		if(howManyGuess<=level){
			res=res+"["+xPos+","+yPos+"]= {.";
			for(int i=0;i<guess.getVectorSDK().length;i++)
				res=res+guess.getVectorSDK()[i]+".";
			res=res+"} "+howManyGuess;
			System.out.println(res);
		}
		
	}

	public int getHowManyGuess()
	{
		return howManyGuess;
	}

	public void setHowManyGuess(int howManyGuess)
	{
		this.howManyGuess = howManyGuess;
	}

	/**
	 * return singleton value
	 * if is not singleton return NULL
	 * @return
	 */
	
	public String getSingleGuess()
	{
		if(this.howManyGuess==1){
			for(int i=0;i<9;i++){
				if (!guess.getVectorSDK()[i].equals(""))
					return guess.getVectorSDK()[i];
			}
		}
		return null;
	}
	
	public String getGuessLine(){
		String res="";
		for(int i=0;i<9;i++){
			if (!guess.getVectorSDK()[i].equals(""))
					{
				res=res+guess.getVectorSDK()[i];
			}else{

				res=res+" ";
			}
					
		}
		return " ["+res+"]";
	}

	public VectorSDK getGuess()
	{
		return guess;
	}

	public void setGuess(VectorSDK guess)
	{
		this.guess = guess;
	}
	
}
